{extend name="$base" /}
{block name="resources"}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style>
label {float:left;text-align: left;font-size: 12px;padding:0 10px;overflow:hidden;color:#666;font-weight: normal;line-height: 32px;margin-bottom:0}
label input[type="radio"]{margin: 0 5px 0 0;} 
</style>
{/block}
{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="color-red">*</span>名称：</dt>
		<dd>
			<input id="link_title" type="text" class="input-common" />
			<p class="error">请输入名称</p>
		</dd>
	</dl>
	<dl>
		<dt>图片：</dt>
		<dd>
			<div class="upload-btn-common">
				<div>
					<input class="input-file" name="file_upload" id="uploadLinkPic" type="file" onchange="imgUpload(this);" title="上传">
					<input type="hidden" id="link_pic" value="">
				</div>
				
				<input type="text" id="text_link_pic" class="input-common" readonly="readonly" value="">
				<em>上传</em>
				<img id="preview_link_pic" src="__STATIC__/blue/img/upload-common-select.png" data-src="" data-html="true" data-container="body" data-placement="top" data-trigger="manual" data-original-title="" title="">
			</div>
			<p class="hint">
				建议使用宽<i class="important-note">100</i>像素-<i class="important-note">高100</i>像素内的<i class="important-note">GIF</i>或<i class="important-note">PNG</i>透明图片</span>
			</p>
			<p class="error">请上传图片</p>
		</dd>
	</dl>
	<dl>
		<dt>是否新窗口打开：</dt>
		<dd>
			<p>
				<input id="navigationtype" type="checkbox"  class="checkbox" />
			</p>
		</dd>
	</dl>
	<dl>
		<dt>是否显示：</dt>
		<dd>
			<p>
				<input id="showtype" type="checkbox"  class="checkbox" />
			</p>
		</dd>
	</dl>
	<dl>
		<dt>链接地址：</dt>
		<dd>
			<p>
				<input id="link_url" type="text" class="input-common long" />
			</p>
		</dd>
	</dl>
	<dl>
		<dt>排序：</dt>
		<dd>
			<p>
				<input id="link_sort" type="number" onkeyup="this.value=this.value.replace(/\D/g,'')" class="input-common harf" />
			</p>
		</dd>
	</dl>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="setConfigAjax();">保存</button>
			<button class="btn-common-cancle btn-big" onclick="javascript:history.back(-1);" >返回</button>
		</dd>
	</dl>
</div>
<script src="__STATIC__/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script>
//图片上传
function imgUpload(event) {
	var fileid = $(event).attr("id");
	var id = $(event).next().attr("id");
	var data = { 'file_path' : "config" };
	uploadFile({
		url: __URL(ADMINMAIN + '/config/uploadimage'),
		fileId: fileid,
		data : data,
		callBack: function (res) {
			if(res.code){
				$("#" + id).val(res.data.path);
				$("#text_" + id).val(res.data.path);
				$("#preview_"+ id).attr("data-src",__IMG(res.data.path));
				showTip(res.message,"success");
			}else{
				showTip(res.message,"error");
			}
		}
	});
}

function setConfigAjax() {
	var link_title = $("#link_title").val();
	var link_url = $("#link_url").val();
	var link_pic = $("#link_pic").val();
	var link_sort = $("#link_sort").val();
	var is_blank = $("#navigationtype").prop('checked') ? 1 : 0 ;
	var is_show = $("#showtype").prop('checked') ? 1 : 0 ;
	if(link_title.length == 0){
		$("#link_title").next(".error").show();
		return false;
	}else{
		$(".error").hide();
	}
	$.ajax({
		type : "post",
		url : "{:__URL('ADMIN_MAIN/config/addlink')}",
		data : {
			'link_title' : link_title,
			'link_url' : link_url,
			'link_pic' : link_pic,
			'link_sort' : link_sort,
			'is_blank' : is_blank,
			'is_show' : is_show
		},
		success : function(data) {
			if (data["code"] > 0) {
				showTip(data["message"],'success');
				window.location.href = "{:__URL('ADMIN_MAIN/config/linklist')}";
			} else {
				showTip(data["message"],'error');
			}
		}
	});
}
</script>
{/block}